/*
 * @Author: szx
 * @Date: 2022-04-27 14:24:31
 * @LastEditTime: 2022-04-27 14:31:47
 * @Description:
 * @FilePath: \leetcode\300-399\398\398.js
 */
/**
 * @param {number[]} nums
 */
var Solution = function (nums) {};

/**
 * @param {number} target
 * @return {number}
 */
Solution.prototype.pick = function (target) {};

/**
 * Your Solution object will be instantiated and called as such:
 * var obj = new Solution(nums)
 * var param_1 = obj.pick(target)
 */ /**
 * @param {number[]} nums
 */
var Solution = function (nums) {
    const map = new Map();
    for (let [key, value] of nums.entries()) {
        if (!map.has(value)) {
            map.set(value, []);
        }
        map.get(value).push(key);
    }
    this.map = map;
};

/**
 * @param {number} target
 * @return {number}
 */
Solution.prototype.pick = function (target) {
    const arr = this.map.get(target);
    const index = Math.floor(Math.random() * arr.length);
    return arr[index];
};

/**
 * Your Solution object will be instantiated and called as such:
 * var obj = new Solution(nums)
 * var param_1 = obj.pick(target)
 */
